#include "stdafx.h"
#include "RootView.h"
#include "View.h"
#include "LayoutHorizontal.h"
#include "LayoutVertical.h"
#include "Button.h"
#include "SkCanvas.h"

RootView::RootView()
	: View(NULL)
{
}


RootView::~RootView()
{
}

bool RootView::onPaint(SkCanvas* canvas)
{
	canvas->save();

	if (canvas->clipRect(X(), Y(), Width(), Height()))
	{
		canvas->translate(X(), Y());

		PARENT::onPaint(canvas);

	}
	
	canvas->restore();


/*
#ifdef DEBUG
	if (!m_layout->onPaint(canvas))
	{
		return false;
	}

#endif
*/
	return true;
}

bool RootView::updateLayout()
{
	if (m_layout)
	{
		m_layout->setRect(0, 0, Width(), Height());
		m_layout->updateLayout();
	}

	return true;
}

bool RootView::paint(SkCanvas* canvas)
{
	if (canvas == NULL)
	{
		ATLTRACE("[%s][%d]\r\n", __FUNCTION__, __LINE__);
		return false;
	}

	if (canvas)
	{
		canvas->FillRect(SkColor(51, 51, 53), 0, 0, Width(), Height());  // black

		//signal
		SkFont font(std::wstring(L"Andalus"), 11);
		canvas->drawText(std::wstring(L"Power By: mfcjck"), font, SkColor(255, 255, 255, 128), 0, Height() - 20, Width(), 20);
	}

	return true;
}


Layout* RootView::getLayout()
{
	return m_layout;
}

void RootView::setLayout(Layout* layout)
{
	m_layout = layout;
}


View* RootView::getViewById(uint32 id)
{
	for (std::list<View*>::iterator iter = m_childViews.begin(); iter != m_childViews.end(); ++iter)
	{
		if (*iter)
		{
			View* view = (*iter)->getViewById(id);
			if (view != NULL)
			{
				return view;
			}
		}
	}

	return NULL;
}
